package com.appcheck.recording.listener.impl;

import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnGroupClickListener;

import com.appcheck.recording.ListenerManager;
import com.appcheck.recording.WidgetHelper;
import com.appcheck.recording.action.impl.ItemClickAction;
import com.appcheck.recording.listener.AbstractListener;
import com.appcheck.recording.utils.Logger;

public class GrouperClickListener extends AbstractListener implements
		OnGroupClickListener {

	private int b;
	
	public GrouperClickListener(View paramView) {
		super(paramView, ExpandableListView.class, ExpandableListView.OnGroupClickListener.class);
	}

	@Override
	public boolean onGroupClick(ExpandableListView parent, View v,
			int groupPosition, long id) {
		if (this.b++ > 1) {
		      return false;
		}
		//groupPosition是组的位置，id和groupPosition相同
		//Logger.INFO("onGroupClick groupPosition = " + groupPosition + ", " + " id = " + id + ", parent.indexOfChild = " + parent.indexOfChild(v)+ ", " + "parent.getPositionForView = " + parent.getPositionForView(v));
	    ItemClickAction itemClickAction = new ItemClickAction();
	    itemClickAction.setLine(parent.getPositionForView(v));
	    itemClickAction.setLongClick(false);
	    itemClickAction.setParentResourceName(WidgetHelper.getResourceName(parent));
	    itemClickAction.setParentResourceId(WidgetHelper.getResourceId(parent));
	    ListenerManager.getListenerManager().handleAction(itemClickAction);
		ListenerManager.getListenerManager().clean();
	    if (this.listener != null){
	      boolean bool = ((ExpandableListView.OnGroupClickListener)this.listener).onGroupClick(parent, v, groupPosition, id);      
	      this.b = 0;
	      return bool;
	    }
	    this.b = 0;
	    return false;
	}

}
